import {readFile} from '../../../src/utils'
import {Coverage} from '../../../src/test-parser'
import {PytestParser} from '../../../src/parsers/python-pytest/pytest-parser'
import {expect} from 'chai'

describe('count', () => {

    it('should correctly calculate coverage from the HTML content', async () =>{

        const mavenData = await readFile('./test/parsers/python-pytest/pytest-result.html')
        const expectedCoverage: Coverage = {
            total: 110,
            passed: 109,
            failed: 1,
            skipped: 0,
            passedRate: 99.09
        };

        const pytestParser = new PytestParser()
        const res = await pytestParser.count(mavenData)
        expect(res).to.deep.equal(expectedCoverage)
    })
})

describe('File Path Converters', () => {
    describe('coverageFile', () => {
        it('should throw an error if the path does not end with .html', async () => {
            try {
                const invalidPath = 'path/to/report.json';
                const pytestParser = new PytestParser()
                await pytestParser.coverageFile(invalidPath);
                expect.fail('Expected error was not thrown');
            } catch (error) {
                expect(error).to.be.an('error');
                // @ts-ignore
                expect(error.message).to.equal(`Input variable 'reportPath' should reference a report with html extension`);
            }
        });
        it('should return the correct path if it ends with .html and exsits', async () => {
            const validPath = './test/parsers/python-pytest/pytest-result.html';
            const pytestParser = new PytestParser()
            const result = await pytestParser.coverageFile(validPath);
            expect(result).to.equal(validPath);
        });
    });
    describe('htmlFile', () => {
        it ('should return the same path', () => {
            const path = './test/parsers/python-pytest/pytest-result.html'
            const pytestParser = new PytestParser()
            expect(pytestParser.htmlFile(path)).to.equal(path)
        })
    });
});